package com.its.classTable.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.its.classTable.mapper.ClassTableMapper;
import com.its.classTable.pojo.ClassTable;
import com.its.classTable.service.ClassTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;

/**
* @author lenovo
* @description 针对表【gym_class_table】的数据库操作Service实现
* @createDate 2025-04-22 23:47:58
*/
@Service
public class ClassTableServiceImpl extends ServiceImpl<ClassTableMapper, ClassTable> implements ClassTableService {
    //依赖注入Mapper层属性
    @Autowired
    private ClassTableMapper classTableMapper;


    //新增课程信息
    @Override
    public int addClassTable(ClassTable classTable) {
        return classTableMapper.insert(classTable);
    }

    //删除课程信息
    @Override
    public int deleteClassTable(Integer classId) {
        return classTableMapper.deleteById(classId);
    }

    //跟新课程表信息
    @Override
    public int updateClassTable(ClassTable classTable) {
        return classTableMapper.updateById(classTable);
    }

    //根据关键字查询课程信息
    @Override
    public List<ClassTable> selectClassTableByKeyword(String keyword) {
        //1.校验关键字
        if(StringUtils.isEmpty(keyword)){
            return Collections.emptyList();
        }

        QueryWrapper<ClassTable> queryWrapper = new QueryWrapper<>();
        keyword = keyword.trim(); // 去除首尾空格
        queryWrapper.like("class_name",keyword)
                .or()
                .like("class_begin",keyword)
                .or()
                .like("class_time",keyword)
                .or()
                .like("coach",keyword);
        return classTableMapper.selectList(queryWrapper);
    }

    //分页查询所有课程信息
    @Override
    public Page<ClassTable> selectAllClassTable(Integer page, Integer size) {
        return classTableMapper.selectPage(new Page<>(page,size),null);
    }
}




